package com.skt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.skt.domain.PO.Costume;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface CostumeMapper extends BaseMapper<Costume> {

    /**
     * 根据订单ID回补服装库存（归还时调用）
     * 假设 rental_order_item 表记录了订单中每个服装及其数量
     *
     * @param orderId 订单ID
     */
    @Update("""
        UPDATE costume c
        INNER JOIN rental_order_item roi ON c.id = roi.costume_id
        SET c.stock = c.stock + roi.quantity
        WHERE roi.order_id = #{orderId}
        """)
    void increaseStockByOrderId(@Param("orderId") Long orderId);
}